10 REM: MODIFIED FOR ALTAIR BASIC BY ROGER AMIDON AND DOUG MOSER.
20 PRINT:PRINT:PRINT TAB(15);"******  S T A R   T R E K  ******"
25 PRINT:PRINT
30 DIM G(8,8),Q(8,8),D(6),K(9,3),N(3),Q$(5),D$(6)
40 Q$(1)="   ":Q$(2)="<*>":Q$(3)="+++":Q$(4)=">!<":Q$(5)=" * "
45 D$(1)="WARP ENGINES":D$(2)="S.R. SENSORS":D$(3)="L.R. SENSORS"
48 D$(4)="PHASER CONTROL":D$(5)="PHOTON TUBES":D$(6)="DAMAGE CONTROL"
70 T0=INT(RND(1)*20+20)*100
80 T=T0
90 T9=40
100 E=3000:E0=3000
110 P=10:P0=10
120 S9=200
130 DEF FND(D)=SQR((K(I,1)-S1)^2+(K(I,2)-S2)^2)
140 Q1=INT(RND(1)*8+1)
150 Q2=INT(RND(1)*8+1)
170 S1=INT(RND(1)*8+1)
180 S2=INT(RND(1)*8+1)
190 REM: SET UP GALAXY
200 K9=0:B9=0
210 FOR I=1 TO 8
220 FOR J=1 TO 8
230 R=RND(1)*64
240 GOSUB 3920
250 K9=K9+K3
260 IF RND(1)>.96 THEN 290
270 B3=0
280 GOTO 300
290 B3=1
300 B9=B9+B3
310 S3=INT(RND(1)*8+1)
320 G(I,J)=K3*100+B3*10+S3
330 NEXT J
340 NEXT I
350 K0=K9
360 IF B9>0 THEN 410
370 I=RND(1)*8+.5
380 J=RND(1)*8+.5
390 G(I,J)=G(I,J)+10
400 B9=1
410 GOSUB 3770
420 REM: SET UP QUADRANT
430 K3=0:B3=0:S3=0
440 IF Q1<1 THEN 530
450 IF Q1>8 THEN 530
460 IF Q2<1 THEN 530
470 IF Q2>8 THEN 530
480 X=G(Q1,Q2)/100
490 K3=INT(X)
500 B3=INT((X-K3)*10)
510 S3=G(Q1,Q2)-INT(G(Q1,Q2)*.1)*10
530 FOR I=1 TO 8
540 FOR J=1 TO 8
550 Q(I,J)=0
560 NEXT J
570 NEXT I
580 Q(S1,S2)=1
585 IF K3<1 THEN 655
590 FOR I=1 TO K3
600 GOSUB 3720
610 Q(R1,R2)=2
620 K(I,1)=R1
630 K(I,2)=R2
640 K(I,3)=S9
650 NEXT I
655 IF B3<1 THEN 695
660 FOR I=1 TO B3
670 GOSUB 3720
680 Q(R1,R2)=3
690 NEXT I
695 IF S3<1 THEN 740
700 FOR I=1 TO S3
710 GOSUB 3720
720 Q(R1,R2)=4
730 NEXT I
740 A=-1
750 REM: SHORT RANGE SENSOR SCAN
760 GOSUB 4120
770 FOR I= W1 TO W2
780 FOR J= W3 TO W4
790 IF Q(I,J) <> 3 THEN 840
800 C$="DOCKED"
810 E=3000
820 P=10
830 GOTO 960
840 NEXT J
850 NEXT I
860 IF K3>0 THEN 930
870 IF E<E0*.1 THEN 950
880 FOR I=1 TO 6
890 IF D(I)<0 GOTO 950
900 NEXT I
910 C$="GREEN"
920 GOTO 960
930 C$="RED"
940 GOTO 960
950 C$="YELLOW"
960 IF A>0 GOTO 980
970 GOSUB 3410
980 IF E <= 0 THEN 3530
990 IF D(2) >= 0 THEN 1040
1000 PRINT
1010 PRINT "***SHORT RANGE SENSORS ARE OUT ***"
1020 PRINT
1030 GOTO 1290
1040 EW$= "-------------------------------"
1041 PRINT EW$
1050 FOR I=1 TO 8
1060 FOR J=1 TO 8
1070 PRINT Q$(Q(I,J)+1);:PRINT " ";
1080 NEXT J
1090 PRINT "   ";
1100 ON I GOTO 1150,1170,1190,1210,1230,1250,1270,1110
1110 PRINT
1120 NEXT I
1130 PRINT EW$
1140 GOTO 1290
1150 PRINT "STARDATE";T
1160 GOTO 1120
1170 PRINT "CONDITION ";C$
1180 GOTO 1120
1190 PRINT "QUADRANT";Q1;"-";Q2
1200 GOTO 1120
1210 PRINT "SECTOR";S1;"-";S2
1220 GOTO 1120
1230 PRINT "ENERGY";E
1240 GOTO 1120
1250 PRINT "PHOTON TORPEDOES";P
1260 GOTO 1120
1270 PRINT "KLINGONS LEFT";K9
1280 GOTO 1120
1290 PRINT "COMMAND, CAPTAIN:";
1300 INPUT A
1310 IF A>7 THEN 1420
1320 ON A+1 GOTO 1440,750,2180,2380,2620,3170,1330,7080
1330 PRINT
1340 PRINT "   0 = SET COURSE"
1350 PRINT "   1 = SHORT RANGE SENSOR SCAN"
1360 PRINT "   2 = LONG RANGE SENSOR SCAN"
1370 PRINT "   3 = FIRE PHASERS"
1380 PRINT "   4 = FIRE PHOTON TORPEDOES"
1390 PRINT "   5 = DAMAGE CONTROL REPORT"
1392 PRINT "   6 = LIST OF COMMANDS"
1394 PRINT "   7 = GALAXY DISPLAY"
1400 PRINT
1410 GOTO 1290
1420 PRINT"DEMOTED 2 STEPS IN RANK. TYPE 6 AFTER 'COMMAND?'"
1430 GOTO 1290
1440 REM: WARP DRIVE
1450 PRINT "COURSE (1-8.9999):";
1460 INPUT C1
1470 IF C1=0 THEN 1290
1480 IF C1<1 THEN 1450
1490 IF C1 >= 9 THEN 1450
1500 PRINT "WARP FACTOR (0-12):";
1510 INPUT W1
1515 IF T/5<>INT(T/5) THEN 1520
1518 GOSUB 4390
1520 IF W1<0 THEN 1450
1530 IF W1>12 THEN 1450
1540 IF W1 <= .2 THEN 1580
1550 IF D(1) >= 0 THEN 1580
1560 PRINT "WARP ENGINES ARE DAMAGED, MAXIMUM SPEED = WARP .2"
1570 GOTO 1450
1580 IF K3 <= 0 THEN 1610
1590 GOSUB 3410
1600 IF E <= 0 THEN 3560
1610 FOR I=1 TO 6
1620 D(I)=D(I)+1
1630 IF  D(I)<0 THEN 1650
1640 D(I)=0
1650 NEXT I
1660 IF RND(1)>.25 THEN 1870
1670 R1=INT(RND(1)*6+1)
1680 IF RND(1)>.5 THEN 1730
1690 D(R1)=D(R1)-(RND(1)*5+1)
1700 PRINT"*** SPACE STORM, ";D$(R1);" DAMAGED ***"
1710 S=0
1720 GOTO 1870
1730 FOR I=R1 TO 6
1740 IF D(I)<0 THEN 1800
1750 NEXT I
1760 FOR I=1 TO R1-1
1770 IF D(I)<0 THEN 1800
1780 NEXT I
1790 GOTO 1860
1800 R1=I
1810 IF D(I)*RND(1)*5+1>0 GOTO 1840
1820 D(I)=D(I)*RND(1)*.5+1
1830 GOTO 1850
1840 D(I)=0
1850 PRINT"*** TRUCE, ";D$(R1);" STATE OF REPAIR IMPROVED ***"
1860 S=0
1870 N=INT(W1*8)
1880 E=E-N-N+5
1890 T=T+1
1900 Q(S1,S2)=0
1910 X=S1
1920 Y=S2
1930 IF T>T0+T9 THEN 3530
1940 GOSUB 3140
1950 FOR I=1 TO N
1960 S1=S1+X1
1970 S2=S2+X2
1980 IF S1<.5 GOTO 2120
1990 IF S2<.5 GOTO 2120
2000 IF S1>=8.5 GOTO 2120
2010 IF S2>=8.5 GOTO 2120
2020 IF Q(S1+.5,S2+.5)=0 THEN 2070
2030 PRINT "ENTERPRISE BLOCKED BY OBJECT AT SECTOR"S1;"-"S2
2040 S1=S1-X1
2050 S2=S2-X2
2060 GOTO 2080
2070 NEXT I
2080 Q(S1+.5,S2+.5)=1
2090 S1=INT(S1+.5)
2100 S2=INT(S2+.5)
2110 GOTO 750
2120 Q1=INT(Q1+W1*X1+(X-.5)/8)
2130 Q2=INT(Q2+W1*X2+(Y-.5)/8)
2140 GOSUB 4290
2150 S1=INT(RND(1)*8+1)
2160 S2=INT(RND(1)*8+1)
2170 GOTO 420
2180 REM: LONG RANGE SENSOR SCAN
2190 IF D(3) >= 0 THEN 2220
2200 PRINT "LONG RANGE SENSORS ARE INOPERABLE"
2210 GOTO 1290
2220 PRINT "LONG RANGE SENSOR SCAN FOR QUADRANT"Q1","Q2
2230 EX$= "------------------- "
2231 PRINT EX$
2250 FOR I=Q1-1 TO Q1+1
2260 N(1)=0:N(2)=0:N(3)=0
2270 FOR J=Q2-1 TO Q2+1
2280 IF I<1 THEN 2330
2290 IF I>8 THEN 2330
2300 IF J<1 THEN 2330
2310 IF J>8 THEN 2330
2320 N(J-Q2+2)=G(I,J)
2330 NEXT J
2340 PRINT ": ";:AB=N(1):GOSUB 7135:PRINT " : ";:AB=N(2):GOSUB 7135
2342 PRINT " : ";:AB=N(3):GOSUB 7135:PRINT " :"
2350 PRINT EX$
2360 NEXT I
2370 GOTO 1290
2380 REM: PHASER CONTROL
2390 IF D(4) >= 0 THEN 2420
2400 PRINT "PHASER CONTROL IS DISABLED"
2410 GOTO 1290
2420 PRINT "PHASERS LOCKED ON TARGET.  ENERGY AVAILABLE = "E
2430 PRINT "NUMBER OF UNITS TO FIRE:";
2440 INPUT X
2450 IF X <= 0 THEN 1290
2460 IF E-X<0 THEN 2420
2470 E=E-X
2480 IF K3=0 THEN 2590
2490 FOR I=1 TO 9
2500 IF K(I,3) <= 0 THEN 2580
2510 H=X/FND(0)*(2+RND(1))
2520 K(I,3)=K(I,3)-H
2530 PRINT H;"UNIT HIT ON KLINGON AT SECTOR"K(I,1);"-"K(I,2)
2540 PRINT "("K(I,3)"LEFT)"
2550 IF K(I,3)>0 THEN 2580
2560 GOSUB 3350
2570 IF K9 <= 0 THEN 3630
2580 NEXT I
2590 GOSUB 3410
2600 IF E <= 0 THEN 3560
2610 GOTO 1290
2620 REM: PHOTON TORPEDOES
2630 IF D(5) >= 0 THEN 2660
2640 PRINT "PHOTON TUBES ARE NOT OPERATIONAL"
2650 GOTO 1290
2660 IF P>0 THEN 2690
2670 PRINT "ALL PHOTON TORPEDOES EXPENDED"
2680 GOTO 1290
2690 PRINT"TORPEDO COURSE (1-8.9999):";
2700 INPUT C1
2710 IF C1=0 THEN 1290
2720 IF C1<1 THEN 2690
2730 IF C1 >= 9 THEN 2690
2740 GOSUB 3140
2750 X=S1
2760 Y=S2
2770 P=P-1
2780 PRINT "TORPEDO TRACK:";
2790 X=X+X1
2800 Y=Y+X2
2810 IF Y<.5 GOTO 3100
2820 IF X<.5 GOTO 3100
2830 IF X>8.5 GOTO 3100
2840 IF Y>8.5 GOTO 3100
2850 PRINT X;"-"Y;
2860 IF Q(X+.5,Y+.5)=1 GOTO 2790
2870 IF Q(X+.5,Y+.5)<>0 THEN 2890
2880 GOTO 2790
2890 IF Q(X+.5,Y+.5)<>2 THEN 3000
2900 PRINT "*** KLINGON DESTROYED ***"
2910 K3=K3-1
2920 K9=K9-1
2930 IF K9 <= 0 THEN 3630
2940 FOR I=1 TO 9
2950 IF INT(Y+.5) <>K(I,2)THEN 2970
2960 IF INT(X+.5)=K(I,1) THEN 2980
2970 NEXT I
2980 K(I,3)=0
2990 GOTO 3070
3000 IF Q(X+.5,Y+.5)<>4 THEN 3040
3010 PRINT "STAR DESTROYED"
3020 S3=S3-1
3030 GOTO 3070
3040 PRINT
3050 PRINT "*** STAR BASE DESTROYED ... CONGRATULATIONS ***"
3060 B3=B3-1
3070 Q(X+.5,Y+.5)=0
3080 G(Q1,Q2)=K3*100+B3*10+S3
3090 GOTO 3110
3100 PRINT "TORPEDO MISSED"
3110 GOSUB 3410
3120 IF E <= 0 THEN 3560
3130 GOTO 1290
3140 X2=COS((C1-1)*.785398)
3150 X1=-SIN((C1-1)*.785398)
3160 RETURN
3170 REM: DAMAGE CONTROL REPORT
3180 IF D(6) >= 0 THEN 3210
3190 PRINT "DAMAGE CONTROL REPORT IS NOT AVAILABLE"
3200 GOTO 1290
3210 PRINT
3220 Z=1
3230 PRINT "DEVICE         STATE OF REPAIR"
3240 V=0
3250 FOR I=1 TO 5
3260 IF D(I)>=0 THEN 3280
3270 PRINT D$(I),INT(D(I));" TURNS"
3280 V=V+D(I)
3290 NEXT I
3300 IF V<0 THEN 3320
3310 PRINT "ALL SYSTEMS","    GO"
3320 PRINT
3330 GOTO 1290
3340 REM:
3350 PRINT "KLINGON AT SECTOR"K(I,1);"-"K(I,2);"DESTROYED!"
3360 K3=K3-1
3370 K9=K9-1
3380 Q(K(I,1),K(I,2))=0
3390 G(Q1,Q2)=K3*100+B3*10+S3
3400 RETURN
3410 REM: KLINGON ATTACK
3420 IF C$ <> "DOCKED" THEN 3450
3430 PRINT "STAR BASE SHIELDS PROTECT THE ENTERPRISE"
3440 RETURN
3450 IF G(Q1,Q2)<100 THEN RETURN
3455 FOR I=1 TO 9
3460 IF K(I,3) <= 0 THEN 3510
3470 H=(K(I,3)/FND(0))*(2+RND(1))
3480 E=E-H
3490 PRINT H;"UNIT HIT ON ENTERPRISE FROM KLINGON AT SECTOR"K(I,1);"-";
3495 PRINT K(I,2)
3500 PRINT "("E;"LEFT)"
3510 NEXT I
3520 RETURN
3530 REM: LOSE
3540 GOSUB 4380
3550 PRINT "IT IS STARDATE"T
3560 GOTO 3580
3570 GOSUB 4380
3580 PRINT "THE ENTERPRISE HAS BEEN DESTROYED   "
3590 PRINT "THE FEDERATION WILL BE CONQUERED."
3600 PRINT "THERE ARE STILL"K9;"KLINGON BATTLE CRUISERS."
3610 PRINT "YOU ARE DEAD."
3620 END
3630 REM: WIN
3640 GOSUB 4380
3650 PRINT "IT IS STARDATE"T
3660 PRINT "THE LAST KLINGON BATTLE CRUISER IN THE GALAXY HAS BEEN"
3670 PRINT "DESTROYED."
3680 PRINT "THE FEDERATION HAS BEEN SAVED"
3690 PRINT "YOU HAVE BEEN PROMOTED TO ADMIRAL."
3700 PRINT K0;"KLINGONS IN"T-T0;"YEARS.  RATING ="INT(K0/(T-T0)*1000)
3710 GOTO 7180
3720 REM: RANDOM NUMBER GENERATOR
3730 R1=INT(RND(1)*8+1)
3740 R2=INT(RND(1)*8+1)
3750 IF Q(R1,R2) <> 0 THEN 3730
3760 RETURN
3770 PRINT "ORDERS:  STARDATE = "T
3780 PRINT"TO: COMMANDER - UNITED STARSHIP ENTERPRISE"
3790 PRINT
3800 PRINT"    THE KLINGON VANGUARD OF"K9"BATTLE CRUISERS HAS INVADED"
3810 PRINT"YOUR PATROL AREA. IF THEY ARE NOT DESTROYED IN"T9"STARDATES
3820 PRINT"(I.E. STARDATE"T0+T9") THE FEDERATION COUNSIL WILL ";
3825 PRINT "SURRENDER"
3830 PRINT"DUE TO THE THREAT OF ROMULAN INTERVENTION. AT LEAST ONE"
3840 PRINT"STARBASE IS KNOWN TO HAVE SURVIVED KLINGON DETECTION AND"
3850 PRINT"DESTRUCTION. IT MAY BE USEFUL FOR PURPOSES OF RESUPPLY."
3860 PRINT"THE ENTERPRISE IS CURRENTLY IN QUADRANT"Q1"-"Q2"SECTOR"
3870 PRINT S1"-"S2". GOOD LUCK."
3880 PRINT TAB(30);"SIGNED,"
3890 PRINT TAB(20);"ADM. RICHARD J. PACKARD"
3900 PRINT TAB(20);"COMMANDER: EARTH FORCES - STAR FLEET COMMAND"
3910 RETURN
3920 K3=0
3930 IF R>1E-04 GOTO 3950
3940 K3=K3+1
3950 IF R>.01 GOTO 3970
3960 K3=K3+1
3970 IF R>.03 GOTO 3990
3980 K3=K3+1
3990 IF R>.08 GOTO 4010
4000 K3=K3+1
4010 IF R>.28 GOTO 4030
4020 K3=K3+1
4030 IF R>1.28 GOTO 4050
4040 K3=K3+1
4050 IF R>3.28 GOTO 4070
4060 K3=K3+1
4070 IF R>6.28 GOTO 4090
4080 K3=K3+1
4090 IF R>13.28 GOTO 4110
4100 K3=K3+1
4110 RETURN
4120 IF S1-1<1 GOTO 4150
4130 W1=S1-1
4140 GOTO 4160
4150 W1=1
4160 IF S1+1>8 GOTO 4190
4170 W2=S1+1
4180 GOTO 4200
4190 W2=8
4200 IF S2-1<1 GOTO 4230
4210 W3=S2-1
4220 GOTO 4250
4230 W3 = 1
4240 IF S2+1>8 GOTO 4270
4250 W4=S2+1
4260 GOTO 4280
4270 W4=8
4280 RETURN
4290 IF Q1<8 GOTO 4310
4300 Q1=8
4310 IF Q1>1 GOTO 4330
4320 Q1=1
4330 IF Q2<8 GOTO 4350
4340 Q2=8
4350 IF Q2>1 THEN RETURN
4360 Q2=1
4380 RETURN
4390 REM- COMMERCIALS -
4395 IF T/15=INT(T/15) THEN 7000
4400 IF T/10=INT(T/10) THEN 6000
5000 PRINT"************ STAR TREK IS BROUGHT TO YOU BY : **************
5005 PRINT"=========="
5010 PRINT"!++++++++!                TTTTT  A    N  N  GGG"
5015 PRINT"==========                  T   A A   NN N G"
5020 PRINT"!        !                  T  AAAAA  N NN G  GG"
5025 PRINT"!--------!                  T A     A N  N  GGG"
5030 PRINT"!  TANG  !"
5035 PRINT"!  TANG  !     SPOCK: SPOCK TO CAPTAIN KIRK. KLINGON BATTLE"
5040 PRINT"!  TANG  !           CRUISERS SIGHTED. CONDITION RED."
5045 PRINT"!        !           APPEARANCE ON BRIDGE REQUESTED."
5050 PRINT"! ORANGE !"
5055 PRINT"! FLAVOR !     KIRK: NOT NOW SPOCK. I'M DRINKING"
5060 PRINT"!--------!           MY TANG."
5065 PRINT"=========="
5070 PRINT
5075 PRINT
5080 PRINT"    DRINK TANG ***** CAPTAIN KIRK DOES. *****"
5085 PRINT
5090 PRINT"************************************************************
5095 RETURN
6000 PRINT"************* STAR TREK IS BROUGHT TO YOU BY : *************
6005 PRINT
6010 PRINT"      ---                                FFFF  OO  RRR  DDD"
6015 PRINT"    +    +                               F    O  O R  R D  D
6020 PRINT"   +      +                              FFF  O  O RRR  D  D
6025 PRINT"  +        +                             F     OO  R  R DDD"
6030 PRINT" +   QQQQ   +                            F"
6035 PRINT" +   !  !   +"
6040 PRINT" +   !  !   +"
6045 PRINT"  +  !  !  +"
6050 PRINT"   + !  ! +"
6055 PRINT"    +!  !+"
6060 PRINT"     +--+"
6065 PRINT"     !//!    FORD HAS A BETTER IDEA."
6070 PRINT"     !//!"
6075 PRINT"     !//!                       (FORD OF PARMA, OHIO)"
6080 PRINT"     -++-"
6085 PRINT"      --"
6090 PRINT
6095 PRINT"************************************************************
6100 RETURN
7000 PRINT"************* STAR TREK IS BROUGHT TO YOU BY : *************
7005 PRINT
7010 PRINT"   IIIIIIIIII   BBBBB     MM     MM"
7015 PRINT"       II       BB   B    MMM   MMM"
7020 PRINT"       II       BB   B    MMMM MMMM"
7030 PRINT"       II       BBBBB     MM MMM MM"
7035 PRINT"       II       BB   B    MM  M  MM"
7040 PRINT"       II       BB    B   MM     MM"
7045 PRINT"   IIIIIIIIII   BBBBBB    MM     MM"
7050 PRINT
7055 PRINT"                                   NOT JUST DATA -"
7060 PRINT"                                             BUT REALITY"
7070 PRINT"************************************************************
7075 RETURN
7080 REM: GALAXY DISPLAY COMMAND '7'
7082 PRINT "GALAXY DISPLAY :"
7085 EW$="---------------------------------------------------"
7095 FOR I=1 TO 8
7100 PRINT EW$
7105 FOR J=1 TO 8
7110 PRINT " : ";:AB=G(I,J):GOSUB 7135
7115 NEXT J
7118 PRINT " :"
7120 NEXT I
7125 PRINT EW$
7130 GOTO 1290
7135 REM: ** SIMULATES PRINT USING **
7138 WE$="0":WX$="00"
7140 WY$=STR$(AB)
7145 EZ$=MID$(WY$,2)
7150 LN=LEN(EZ$)
7155 IF LN=1 THEN EZ$=WX$+EZ$
7160 IF LN=2 THEN EZ$=WE$+EZ$
7165 PRINT EZ$;
7170 RETURN
7180 END
